package com.cloudwebrtc.voip.mediaengine.impl;

import com.cloudwebrtc.voip.mediaengine.AudioStream;
import com.cloudwebrtc.voip.mediaengine.CallStatistics;

public class AudioStreamImpl implements AudioStream {
	//implement for AudioStream_JNI.cpp
	private long nativePtr = 0;
	private native int StartSending(long nativePtr);
	private native boolean IsSending(long nativePtr);
	private native int StopSending(long nativePtr);
	private native int StartReceiving(long nativePtr);
	private native boolean IsReceiving(long nativePtr);
	private native int StopReceiving(long nativePtr);
	private native int SetOutputVolumeScaling(long nativePtr,float scaling);
	private native int GetSpeechOutputLevel(long nativePtr);
	private native int MuteMic(long nativePtr,boolean yesno);
	private native int MuteSpk(long nativePtr,boolean yesno);
	private native int GetCallStatisticsFractionLost(long nativePtr);
	private native int GetCallStatisticsRttMs(long nativePtr);
	
	public AudioStreamImpl(long aNativePtr)
	{
		nativePtr = aNativePtr;
	}
	@Override
	public int StartSending() {
		return StartSending(nativePtr);
	}

	@Override
	public boolean IsSending() {
		return IsSending(nativePtr);
	}

	@Override
	public int StopSending() {
		return StopSending(nativePtr);
	}

	@Override
	public int StartReceiving() {
		return StartReceiving(nativePtr);
	}

	@Override
	public boolean IsReceiving() {
		return IsReceiving(nativePtr);
	}

	@Override
	public int StopReceiving() {
		return StopReceiving(nativePtr);
	}

	@Override
	public int SetOutputVolumeScaling(float scaling) {
		return SetOutputVolumeScaling(nativePtr,scaling);
	}

	@Override
	public int GetSpeechOutputLevel() {
		return GetSpeechOutputLevel(nativePtr);
	}

	@Override
	public int MuteMic(boolean yesno) {
		return MuteMic(nativePtr,yesno);
	}

	@Override
	public int MuteSpk(boolean yesno) {
		return MuteSpk(nativePtr,yesno);
	}

	@Override
	public CallStatistics GetCallStatistics() {
		CallStatistics stats = new CallStatistics();
		stats.fractionLost = GetCallStatisticsFractionLost(nativePtr);
		stats.rttMs = GetCallStatisticsRttMs(nativePtr);
		return stats;
	}
}
